@@ -14,6 +14,10 @@ module LiquidInterpolatable |
||
| 14 | 14 |
duped_options |
| 15 | 15 |
end |
| 16 | 16 |
|
| 17 |
+ def interpolate_string string, payload |
|
| 18 |
+ Liquid::Template.parse(string).render(payload) |
|
| 19 |
+ end |
|
| 20 |
+ |
|
| 17 | 21 |
require 'uri' |
| 18 | 22 |
# Percent encoding for URI conforming to RFC 3986. |
| 19 | 23 |
# Ref: http://tools.ietf.org/html/rfc3986#page-12 |
@@ -43,7 +43,7 @@ module Agents |
||
| 43 | 43 |
{
|
| 44 | 44 |
"matchers": [ |
| 45 | 45 |
{
|
| 46 |
- "path": "$.date.pretty", |
|
| 46 |
+ "path": "{{date.pretty}}",
|
|
| 47 | 47 |
"regexp": "\\A(?<time>\\d\\d:\\d\\d [AP]M [A-Z]+)", |
| 48 | 48 |
"to": "pretty_date", |
| 49 | 49 |
} |
@@ -162,7 +162,7 @@ module Agents |
||
| 162 | 162 |
re = Regexp.new(regexp) |
| 163 | 163 |
proc { |hash|
|
| 164 | 164 |
mhash = {}
|
| 165 |
- value = Utils.value_at(hash, path) |
|
| 165 |
+ value = interpolate_string(path, hash) |
|
| 166 | 166 |
if value.is_a?(String) && (m = re.match(value)) |
| 167 | 167 |
m.to_a.each_with_index { |s, i|
|
| 168 | 168 |
mhash[i.to_s] = s |
@@ -12,7 +12,7 @@ describe Agents::EventFormattingAgent do |
||
| 12 | 12 |
:mode => "clean", |
| 13 | 13 |
:matchers => [ |
| 14 | 14 |
{
|
| 15 |
- :path => "$.date.pretty", |
|
| 15 |
+ :path => "{{date.pretty}}",
|
|
| 16 | 16 |
:regexp => "\\A(?<time>\\d\\d:\\d\\d [AP]M [A-Z]+)", |
| 17 | 17 |
:to => "pretty_date", |
| 18 | 18 |
}, |
@@ -27,5 +27,10 @@ shared_examples_for LiquidInterpolatable do |
||
| 27 | 27 |
"escape" => "This should be Hello+world" |
| 28 | 28 |
} |
| 29 | 29 |
end |
| 30 |
+ |
|
| 31 |
+ it "should work for strings" do |
|
| 32 |
+ @checker.send(:interpolate_string, "{{variable}}", @event.payload).should == "hello"
|
|
| 33 |
+ @checker.send(:interpolate_string, "{{variable}} you", @event.payload).should == "hello you"
|
|
| 34 |
+ end |
|
| 30 | 35 |
end |
| 31 | 36 |
end |